﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public List<Patient> patients;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PatientForm pf = new PatientForm();

            if (pf.ShowDialog() == DialogResult.OK)
            {
                patients.Add(pf.p);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = patients;

                DataAccess aA1 = new DataAccess();
                aA1.AppPatient(pf.p);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataAccess dt = new DataAccess();
            patients = dt.list();
            dataGridView1.DataSource = patients;

            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataAccess dt = new DataAccess();
            PatientForm pf = new PatientForm();
            if (pf.ShowDialog() == DialogResult.OK)
            {
                Patient p = new Patient();
                p.id = Convert.ToInt16(textBox2.Text);
                dt.UpdatePatient(p);
            }

            patients = dt.list();
            dataGridView1.DataSource = patients;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Patient p = new Patient();
            p.id = Convert.ToInt16(textBox1.Text);
            DataAccess dt = new DataAccess();
            dt.deletePatient(p);

            patients = dt.list();
            dataGridView1.DataSource = patients;
        }


    }
        public class Patient
        {
            public int id { get; set; }
            public string Name { get; set; }
            public string SurName { get; set; }
            public string Patronymic { get; set; }
            public DateTime dateOfBirth { get; set; }

        }




     
    
}
